﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Hr.DAL;
using Hr.DALContainer;
using Hr.IBLL;
using Hr.IDAL;
using Hr.Model;

namespace Hr.BLL
{
    public partial class MenuService:BaseService<Sys_Menu>,ISys_MenuService
    {
        private MenuDAL dal = new MenuDAL();
        private UserDAL UDAL = new UserDAL();
        private ISys_MenuDAL IMenuDAL = Container.Resolve<ISys_MenuDAL>();
        #region 菜单管理DAL
        #region 查询
        /// <summary>
        /// 获取所有菜单信息集合,包括模糊查询
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetMenuList(string Term)
        {
            return dal.GetMenuList(Term);
        }

        /// <summary>
        /// 条件查询，根据菜单ID查询单个菜单信息
        /// </summary>
        /// <param name="pk_Menu"></param>
        /// <returns></returns>
        public Sys_Menu GetMenuInfo(int pk_Menu)
        {
            return dal.GetModels(n => n.pk_Menu == pk_Menu).SingleOrDefault();
        }


        /// <summary>
        /// 获取类型
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetTypeList()
        {
            return dal.GetTypeList("Sys_Menu").Select(n=>new
            {
                n.ID,
                n.TypeName_CHS
            });
        }
        #endregion


        #region 添加、修改、删除


        /// <summary>
        /// 添加、修改菜单
        /// </summary>
        /// <param name="M"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public bool UpdateMenu(Sys_Menu M ,string Type)
        {
            dal.UpdateMenu(M, Type);
            return dal.SaveChanges();
        }

        public bool DelMenu(int pk_Menu)
        {
            dal.DelMenu(pk_Menu);
            return dal.SaveChanges();
        }
        #endregion
        #endregion
        #region 类型管理DAL
        /// <summary>
        /// 获取所有类型信息，包括模糊查询
        /// </summary>
        /// <returns></returns>
        public List<Sys_TypeID> GetTypeListAll(string Term)
        {
            return dal.GetTypeListAll(Term);
        }

        /// <summary>
        /// 获取审核人信息，分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Dictionary<string,object> GetAuditList(int page,int limit,string Term)
        {

            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"AuditList",dal.GetAuditList(Term).Skip(limit*(page-1)).Take(limit) },
                {"Count",dal.GetAuditList(Term).Count() }
            };
            return dt;
        }

        /// <summary>
        /// 通过id获取用户信息
        /// </summary>
        /// <param name="pk_User"></param>
        /// <returns></returns>
        public User_List GetUserInfo(int pk_User)
        {
            return UDAL.GetUserInfo(pk_User);
        }

        public IEnumerable<object> GetUserMenuList(int pk_User)
        {
            return dal.GetUserMenuList(pk_User);
        }


        /// <summary>
        /// 根据类型ID，获取类型信息
        /// </summary>
        /// <param name="pk_TypeID"></param>
        /// <returns></returns>
        public Sys_TypeID GetTypeInfo(int pk_TypeID)
        {
            return dal.GetTypeInfo(pk_TypeID);
        }


        /// <summary>
        /// 添加、修改类型
        /// </summary>
        /// <param name="T"></param>
        /// <param name="Type"></param>
        /// <param name="pk_User"></param>
        /// <returns></returns>
        public bool UpdateType(Sys_TypeID T,string Type,int pk_User)
        {
            dal.UpdateType(T, Type, pk_User);
            return dal.Savechanges();
        }


        /// <summary>
        /// 删除类型
        /// </summary>
        /// <param name="pk_TypeID"></param>
        /// <returns></returns>
        public bool DelType(Sys_TypeID T)
        {
            dal.DelType(T);
            return dal.SaveChanges();
        }
        #endregion
        public override void SetDal()
        {
            Dal = IMenuDAL;
        }
    }
}
